


/*
Paul Gronke, William D. Hicks (hickswd@appstate.edu), 
     Seth C. McKee, Charles Stewart III, and James Dunham 
   "Voter ID Laws: A View from the Public" in SSQ
*/

/*
.DO file created by William D. Hicks

It reproduces TABLE 1, FIGURES 1-7, and TABLES A3-A4 in 
   Online Appendix.  
 
Last update to this file: 10/16/2017 
This file directs the following tasks:
   (1) label/define/generate variables
   (2) reproduce MODEL for TABLE A3, APPENDIX C
   (3) reproduce FIGURES 2-6 in .pdf files
       - FIGURE1.pdf
	   - FIGURE2.pdf
	   - FIGURE3.pdf
	   - FIGURE4.pdf
	   - FIGURE5.pdf
	   - FIGURE6.pdf
   (4) reproduce TABLE 1 in a .CSV file
       - TABLE_1.csv
   (5) reproduce TABLE A3, APPENDIX C in a .CSV file
       - TABLE_A3.csv
   (6) reproduce TABLE A4, APPENDIX D in a .CSV file
       - FIGURE_A4.csv
   (7) reproduce FIGURES 7a and 7b in a .pdf files
       - FIGURE_7a.pdf
	   - FIGURE7b.pdf
   (8) LOAD data for FIGURES 1a and 1b
   (9) reproduce FIGURES 1a and 1b in .pdf files 
       - FIGURE1a.pdf
	   - FIGURE1b.pdf

*/

/*
                 YOU NEED TO FIRST IMPORT THE .DTA DATASET
                 THIS REQUIRES THAT YOU WRITE YOUR OWN PATH
*/

use ~[FILE PATH]/REPLICATION_DATA_CCES_MODULE.dta, clear 

/*
            OUTPUT (ALL TABLES & GRAPHS) SAVED TO ~DIRECTORY
    -you also need to set the appropriate location for a directory file - 
*/

cd [MAKE YOUR DIRECTORY HERE]


/*                           
                    VARIABLE DEFINITIONS AND LABELS
*/



/*           DEFINING, GENERATING, and MODIFYING VARIABLES                    */



label var strict_photo_id "Respondent lives in strict photo ID state"
label var republican "Respondent identifies as Republican/Republican Leaner" 
label var republican_nolean "Respondent identifies as Republican"
label var democrat "Respondent identifies as Democrat/Democratic Leaner" 
label var democrat_nolean "Respondent identifies as Democrat"
label var independent "Respondent identifies as pure independent" 
label var independent_leaners "Respondent identifies as independent/independent leaner"
label var conserv_ideo "Respondents' ideological self-placement [1-5; liberal-conservative]" 
label var black "Respondent identifies as black, non-Hispanic"
label var hispanic2 "Repondent identifies as Hispanic" 
label var white "Respondent identifies as white, non-Hispanic" 
label var other_race "Respondent identifies as other race, non-Hispanic" 
label var female "Respondent identifies as woman" 
label var south "Respondent resides in Southern state" 
label var educ "Respondents' education [1-6; No HS-Post Grad]" 
label var id_knowledge "Respondent correctly classifies their state's voter ID law" 
label var follows_news "Respondent follows the news [1-4; Hardly-Usually]" 
label var age "Respondent's age" 

/*
     DEPENDENT VARIABLE
*/

/*
reverse three items
*/
gen MCS318_rev=5-MCS318
gen MCS319_rev=5-MCS319
gen MCS321_rev=5-MCS321


/*
put each item on a scale from -1 to 1 
*/

foreach var of varlist MCS316 MCS317 MCS318_rev MCS319_rev MCS320 ///
	MCS321_rev MCS322 {
		gen `var'_1=(`var'*(2/3)-(1+(2/3)))
	}
/*
generate scale, which is each respondent's mean value across these items
*/
alpha MCS316_1 MCS317_1 MCS318_rev_1 MCS319_rev_1 MCS320_1 MCS321_rev_1 MCS322_1, ///
	item gen(voter_ID_scale1)
label var voter_ID_scale1 "voter_ID_scale (-1 to 1)" 
sum voter_ID_scale1


/*     
      PERCEPTION OF VOTER FRAUD SCALE
*/
gen MCS305_rev=5-MCS305
gen MCS306_rev=5-MCS306
gen MCS307_rev=5-MCS307
gen MCS308_rev=5-MCS308
gen MCS309_rev=5-MCS309
gen MCS310_rev=5-MCS310
gen MCS311_rev=5-MCS311
gen MCS312_rev=5-MCS312
gen MCS313_rev=5-MCS313
gen MCS314_rev=5-MCS314

/*
place each item on a -1 to 1 scale
*/

foreach var of varlist MCS305_rev-MCS314_rev ///
{
		gen `var'_1=(`var'*(2/3)-(1+(2/3)))
	}

/*
generate overall scale 
*/
 
alpha MCS305_rev_1-MCS314_rev_1, item gen(fraud_scale1)
label var fraud_scale1 "fraud scale (-1 to 1)" 
sum fraud_scale1

/*
         RACIAL RESENTMENT SCALE
*/
foreach var of varlist CC422a CC422b ///
   {
		gen `var'_1=(`var'*(1/2)-(1.5))
	}
alpha CC422a_1 CC422b_1, item gen(racial_resentment1)
sum racial_resentment1
label var racial_resentment1 "racial_resentment_scale (-1 to 1)"
replace racial_resentment1=0 if white!=1
 
/*
                 FULL INTERACTION MODEL FOR GRAPHS
                      -i.e., APPENDIX C				 
*/ 
quietly regress voter_ID_scale1 i.republican##c.conserv_ideo ///
	i.republican##i.female i.republican##i.black i.republican##i.hispanic2 ///
	i.republican##i.other_race i.republican##c.educ i.republican##c.age i.republican##i.south ///
	i.republican##i.strict_photo_id i.republican##c.fraud_scale1 ///
	i.republican##i.id_knowledge i.republican##c.follows_news /// 
	i.republican##c.racial_resentment1 if republican==1 | democrat==1 [pweight=weight]
estimates store INTERACTIONS

quietly regress voter_ID_scale1 i.republican_nolean##c.conserv_ideo ///
	i.republican_nolean##i.female i.republican_nolean##i.black i.republican_nolean##i.hispanic2 ///
	i.republican_nolean##i.other_race i.republican_nolean##c.educ i.republican_nolean##c.age i.republican_nolean##i.south ///
	i.republican_nolean##i.strict_photo_id i.republican_nolean##c.fraud_scale1 ///
	i.republican_nolean##i.id_knowledge i.republican_nolean##c.follows_news /// 
	i.republican_nolean##c.racial_resentment1 if republican_nolean==1 | democrat_nolean==1 [pweight=weight]
estimates store INTERACTIONS_nolean

/*
run the command using c. to force margins to read median values of 
factor variables
*/
quietly regress voter_ID_scale1 i.republican##c.conserv_ideo ///
	i.republican##c.female i.republican##c.black i.republican##c.hispanic2 ///
	i.republican##c.other_race i.republican##c.educ i.republican##c.age i.republican##c.south ///
	i.republican##c.strict_photo_id i.republican##c.fraud_scale1 ///
	i.republican##c.id_knowledge i.republican##c.follows_news /// 
	i.republican##c.racial_resentment1 if republican==1 | democrat==1 [pweight=weight]
estimates store INTERACTIONS_MARGINS_PLOTS

/*
                MARGINS PLOT FOR IDEOLOGY
				     FIGURE 2
*/

estimates restore INTERACTIONS_MARGINS_PLOTS
quietly margins republican, at(conserv_ideo=(1(1)5) ///
 (median) female (median) black (median) hispanic2 (median) other_race ///
 (mean) educ (mean) age (median) south (median) strict_photo_id ///
 (mean) fraud_scale1 (median) id_knowledge (mean) follows_news (mean) racial_resentment1)
 
 marginsplot, recast(scatter) ///
	plot1opts(mcolor(gs9) msymbol(square)) ///
	plot2opts(mcolor(gs3) msymbol(circle)) ///
    plotregion(margin(l=10 r=10)) ///
	ci1opts(lcolor(gs9) lwidth(medium) lpattern(solid)) ///
	ci2opts(lcolor(gs3) lwidth(medium)) ///
	ytitle(Opinions about the Effects of Voter ID) yscale(range(-1 1)) ylabel(-1(.5)1, labs(small)) ///
	yline(-0.0410929, lwidth(medium) lpattern(dash)) ///
	xtitle(Ideology) title("") xlab(, labs(small)) ///
	legend(order(3 "Democrat" 4 "Republican") rows(1)) scheme(s1mono)
 
graph export FIGURE2.pdf, replace




/* 
                       MARGINS PLOT FOR AGE 
					        FIGURE 3
*/
estimate restore INTERACTIONS_MARGINS_PLOTS
quietly margins republican, at((mean) conserv_ideo ///
 (median) female (median) black (median) hispanic2 (median) other_race ///
 (mean) educ age=(20(10)90) (median) south (median) strict_photo_id ///
 (mean) fraud_scale1 (median) id_knowledge (mean) follows_news (mean) racial_resentment1)
 
 
 marginsplot, recast(scatter) ///
	plot1opts(mcolor(gs9) msymbol(square)) ///
	plot2opts(mcolor(gs3) msymbol(circle)) ///
	ci1opts(lcolor(gs9) lwidth(medium) lpattern(solid)) ///
	ci2opts(lcolor(gs3) lwidth(medium)) ///
	ytitle(Opinions about the Effects of Voter ID) yscale(range(-1 1)) ylabel(-1(.5)1, labs(small)) ///
	yline(-0.0410929, lwidth(medium) lpattern(dash)) ///
	xtitle(Age) title("") xlab(, labs(small)) ///
	legend(order(3 "Democrat" 4 "Republican") rows(1)) scheme(s1mono)
 
graph export FIGURE3.pdf, replace



/*
                            MARGINS PLOT FOR FRAUD SCALE
							         FIGURE 4
*/

estimates restore INTERACTIONS_MARGINS_PLOTS
quietly margins republican, at((mean) conserv_ideo ///
 (median) female (median) black (median) hispanic2 (median) other_race ///
 (mean) educ (mean) age (median) south (median) strict_photo_id ///
 fraud_scale1=(-1(.5)1) (median) id_knowledge (mean) follows_news (mean) racial_resentment1)
 
 
 marginsplot, recast(scatter) ///
	plot1opts(mcolor(gs9) msymbol(square)) ///
	plot2opts(mcolor(gs3) msymbol(circle)) ///
	ci1opts(lcolor(gs9) lwidth(medium) lpattern(solid)) ///
	ci2opts(lcolor(gs3) lwidth(medium)) ///
	ytitle(Opinions about the Effects of Voter ID) yscale(range(-1 1)) ylabel(-1(.5)1, labs(small)) ///
	yline(-0.0410929, lwidth(medium) lpattern(dash)) ///	
	xtitle(Fraud Scale) title("") xlab(, labs(small)) ///
	legend(order(3 "Democrat" 4 "Republican") rows(1)) scheme(s1mono)
 
graph export FIGURE4.pdf, replace



/*
                   MARGINS PLOT FOR FOLLOWING THE NEWS
				             FIGURE 5
*/

estimates restore INTERACTIONS_MARGINS_PLOTS
quietly margins republican, at((mean) conserv_ideo ///
 (median) female (median) black (median) hispanic2 (median) other_race ///
 (mean) educ (mean) age (median) south (median) strict_photo_id ///
 (mean)fraud_scale1 (median) id_knowledge follows_news=(1(1)4) (mean) racial_resentment1)
 
 marginsplot, recast(scatter) ///
	plot1opts(mcolor(gs9) msymbol(square)) ///
	plot2opts(mcolor(gs3) msymbol(circle)) ///
    plotregion(margin(l=10 r=10)) ///
	ci1opts(lcolor(gs9) lwidth(medium) lpattern(solid)) ///
	ci2opts(lcolor(gs3) lwidth(medium)) ///
	ytitle(Opinions about the Effects of Voter ID) yscale(range(-1 1)) ylabel(-1(.5)1, labs(small)) ///
	yline(-0.0410929, lwidth(medium) lpattern(dash)) ///	
	xtitle(Follows the news) title("") xlab(, labs(small)) ///
	legend(order(3 "Democrat" 4 "Republican") rows(1)) scheme(s1mono)
 
graph export FIGURE5.pdf, replace



/*                     MARGINS PLOT FOR RACIAL RESENTMENT
                                   FIGURE 6
*/

estimates restore INTERACTIONS_MARGINS_PLOTS
quietly margins republican, at((mean) conserv_ideo ///
 (median) female  black=(0) hispanic2=(0) other_race=(0) ///
 (mean) educ (mean) age (median) south (median) strict_photo_id ///
 (mean)fraud_scale1 (median) id_knowledge (mean) follows_news racial_resentment1=(-1(.5)1))
 
 
 marginsplot, recast(scatter) ///
	plot1opts(mcolor(gs9) msymbol(square)) ///
	plot2opts(mcolor(gs3) msymbol(circle)) ///
	ci1opts(lcolor(gs9) lwidth(medium) lpattern(solid)) ///
	ci2opts(lcolor(gs3) lwidth(medium)) ///
	ytitle(Opinions about the Effects of Voter ID) yscale(range(-1 1)) ylabel(-1(.5)1, labs(small)) ///
	yline(-0.0410929, lwidth(medium) lpattern(dash)) ///	
	xtitle(Racial resentment scale) title("") xlab(, labs(small)) ///
	legend(order(3 "Democrat" 4 "Republican") rows(1)) scheme(s1mono)
 
graph export FIGURE6.pdf, replace



/*
       Chow Test for Reps v Dems using contrast commands
*/
contrast republican republican#c.conserv_ideo republican#c.female ///
	republican#c.black republican#c.hispanic2 republican#c.other_race ///
	republican#c.educ republican#c.age republican#c.south republican#c.strict_photo_id ///
	republican#c.fraud_scale1 republican#c.id_knowledge republican#c.follows_news ///
	republican#c.racial_resentment1, overall
	
/*F statistic is F(14,1254)=10.30 */

/* 
                       MODELS FOR TABLE 1
*/



global xlist_base republican  democrat conserv_ideo female black ///
	hispanic2 other_race educ age south strict_photo_id fraud_scale1 id_knowledge follows_news racial_resentment1
	
global xlist_base1 republican conserv_ideo female black ///
	hispanic2 other_race educ age south strict_photo_id fraud_scale1 id_knowledge follows_news racial_resentment1
	
global xlist_base2  conserv_ideo female black ///
	hispanic2 other_race educ age south strict_photo_id fraud_scale1 id_knowledge follows_news racial_resentment1



quietly reg voter_ID_scale1 $xlist_base [pweight=weight]
estimates store ALL
	
quietly reg voter_ID_scale1 $xlist_base1 if republican==1 | democrat==1 [pweight=weight]
estimates store Rs_Ds

quietly reg voter_ID_scale1 $xlist_base2 if republican==1 [pweight=weight]
estimates store Rs
	
quietly reg voter_ID_scale1 $xlist_base2 if democrat==1 [pweight=weight]
estimates store Ds

quietly reg voter_ID_scale1 $xlist_base2 if republican_nolean==1 [pweight=weight]
estimates store R_nolean
	
quietly reg voter_ID_scale1 $xlist_base2 if democrat_nolean==1 [pweight=weight]
estimates store D_nolean

/*
                               TABLE 1
*/

estout ALL Rs_Ds Rs Ds using TABLE1.csv, replace cells(b(star fmt(%9.3f)) ///
 se(par(`"="("' `")""'))) starlevels(+ 0.10 * 0.05 ** 0.01) stats(N r2, ///
 fmt(%9.0g %9.3f)) varwidth(50) modelwidth(10) ///
 title("Mass Opinion on Voter ID Laws") ///
 varlabels(_cons constant) ///
 label legend  style(fixed) 
 

/*      
                           TABLE A3, APPENDIX C
*/

 estout INTERACTIONS using TABLE_A3.csv, cells(b(star fmt(%9.3f)) ///
 se(par(`"="("' `")""'))) starlevels(+ 0.10 * 0.05 ** 0.01) stats(N r2, ///
 fmt(%9.0g %9.3f)) varwidth(25) modelwidth(10) ///
 title("Mass Opinion on Voter ID Laws") ///
 varlabels(_cons Constant 1.republican "Republican" ///
 conserv_ideo "Ideology (conservative)" ///
 1.republican#c.conserv_ideo "RepublicanXIdeology" ///
 1.female "Female" 1.republican#1.female "RepublicanXFemale" ///
 1.black "Black" 1.republican#1.black "RepublicanXBlack" ///
 1.hispanic2 "Hispanic" 1.republican#1.hispanic2 "RepublicanXHispanic" ///
 1.other_race "Other Race" 1.republican#1.other_race "RepublicanXOther Race" ///
 1.republican#c.educ "RepublicanXEducation" ///
 age "Age" 1.republican#c.age "RepublicanXAge" 1.south "South" ///
 fraud_scale1 "Fraud Scale" 1.republican#c.fraud_scale1 "RepublicanXFraud Scale" ///
 1.republican#1.south "RepublicanXSouth" 1.strict_photo_id "Strict Photo ID state" ///
 1.republican#1.strict_photo_id "RepublicanXStrict Photo ID state" ///
 1.id_knowledge "Voter ID Knowledge" ///
 1.republican#1.id_knowledge "RepublicanXVoter ID Knowledge" ///
 follows_news "Follows News" 1.republican#c.follows_news "RepublicanXFollows News" ///
 racial_resentment1 "Racial Resentment Scale" ///
 1.republican#c.racial_resentment1 "RepublicanXRacial Resentment Scale") ///
 drop(0.republican 0.republican#c.conserv_ideo 0.female 0.republican#0.female ///
 0.republican#1.female 0.black 0.republican#0.black 0.republican#1.black ///
 0.hispanic2 0.republican#0.hispanic2 0.republican#1.hispanic2 0.other_race ///
 0.republican#0.other_race 0.republican#1.other_race 0.republican#c.educ ///
 0.republican#c.age 0.south 0.republican#0.south 0.republican#1.south ///
 0.strict_photo_id 0.republican#0.strict_photo_id 0.republican#1.strict_photo_id ///
 0.republican#c.fraud_scale1 0.id_knowledge 0.republican#0.id_knowledge ///
 0.republican#1.id_knowledge 0.republican#c.follows_news ///
 0.republican#c.racial_resentment1 1.republican#0.female 1.republican#0.black ///
 1.republican#0.hispanic2 1.republican#0.other_race 1.republican#0.south ///
 1.republican#0.id_knowledge 1.republican#0.strict_photo_id) ///
 legend  

 
/*
                               TABLE A4, APPENDIX D
*/

estout Rs R_nolean Ds D_nolean using TABLE_A4.csv, replace cells(b(star fmt(%9.3f)) ///
 se(par(`"="("' `")""'))) starlevels(+ 0.10 * 0.05 ** 0.01) stats(N r2, ///
 fmt(%9.0g %9.3f)) varwidth(50) modelwidth(10) ///
 title("Mass Opinion on Voter ID Laws") ///
 varlabels(_cons constant) ///
 label legend  style(fixed) 
 
 
 
 /*    PREDICTING SUPPORT FOR VOTER ID LAWS WITH AND WITHOUT
                THE ATTITUDINAL VARIABLE 
 */
 
capture drop idok01 follows_high
recode MCS334 (1/2=1)(3/4=0),gen(idok01) 
recode follows_news (1/2=0)(3/4=1),gen(follows_high) 
capture drop py
probit idok01 i.republican#i.follows_high#c.voter_ID_scale1 if republican==1 | democrat==1 [pweight=weight]
predict py

/*    
                    FIGURE 7a
*/
twoway (line py voter_ID_scale1 if republican==1&follows_high==1, sort lwidth(medthick) lpattern(solid)) ///
       (line py voter_ID_scale1 if republican==1&follows_high==0, sort lcolor(black) lwidth(medthick) lpattern(dash)), ///
	   ytitle(Probability of Supporting Passage of Strict ID Law) yscale(range(0 1)) ///
	   xtitle(Opinions about the Effects of Voter ID) xscale(range(-1 1)) ///
	   legend(on order(1 "High-level news followers"  2 "Low-level news followers") rows(1)) ///
	   scheme(s1mono)
	   
graph export FIGURE7a.pdf, replace



/*    
                    FIGURE 7b
*/
twoway (line py voter_ID_scale1 if republican==0&follows_high==1, sort lwidth(medthick) lpattern(solid)) ///
       (line py voter_ID_scale1 if republican==0&follows_high==0, sort lcolor(black) lwidth(medthick) lpattern(dash)), ///
	   ytitle(Probability of Supporting Passage of Strict ID Law) yscale(range(0 1)) ///
	   xtitle(Opinions about the Effects of Voter ID) xscale(range(-1 1)) ///
	   legend(on order(1 "High-level news followers"  2 "Low-level news followers") rows(1)) ///
	   scheme(s1mono)
	   
graph export FIGURE7b.pdf, replace


/* 
        FIGURES 1a and 1b
*/


/*
                 YOU NEED TO FIRST LOAD THE .DTA DATASET
*/

use ~[FILE PATH]/POLL_DATA_FIGURE_1.dta, clear 



rename *,lower
gen month_txt=substr(date,1,1) if strpos(date,"/")==2
replace month_txt=substr(date,1,2) if strpos(date,"/")==3
gen year=substr(date,-4,4)
gen date_num=date(month+"/15/"+year,"MDY")

twoway (scatter dem date_num, mcolor(gs10) msymbol(circle_hollow)) ///
       (scatter rep date_num, mcolor(gs0) msize(medlarge) msymbol(square_hollow)) ///
	   (scatter total date_num, mcolor(gs5) msymbol(circle)) ///
	   (mband dem date_num, lcolor(gs10) lwidth(medthick) lpattern(longdash_dot) bands(4)) ///
	   (mband rep date_num, lcolor(gs0) lwidth(medthick) lpattern(dash) bands(4)) ///
	   (mband total date_num, lcolor(gs5) lwidth(medthick) lpattern(solid) bands(4)), ///
	   ytitle(Pct. favoring) ///
	   xtitle(Year) ///
	     xlabel(16802 "2006" 17532 "2008" 18263 "2010" 18993 "2012" 19724 "2014") ///
		 xmtick(17167 17898 18628 19359) ///
	   legend(order(1 "Democrats" 2 "Republicans" 3 "All") rows(1)) scheme(s1mono)

graph export FIGURE1a.pdf, replace

twoway (scatter rd date_num, mcolor(black) msize(medium) msymbol(circle)) ///
       (mband rd date_num, lcolor(black) lwidth(medthick) bands(4)), ///
	   ytitle(Republican minus Democrat support) ylabel(0(10)50) ///
	   xtitle(Year) xlabel(16802 "2006" 17532 "2008" 18263 "2010" 18993 "2012" 19724 "2014") ///
	      xmtick(17167 17898 18628 19359) ///
	   legend(off) scheme(s1mono)
graph export FIGURE1b.pdf, replace
